#include <iostream>
#include <chrono>
#include <thread>

class A
{
  private:
  public:
    A()
    {
        std::cout << "construct" << std::endl;
    }
    ~A()
    {
        std::cout << "disconstruct" << std::endl;
    }
    void hello()
    {
        std::cout << "hello" << std::endl;
    }
    A(const A &a)
    {
        std::cout << "A(A& a)拷贝" << std::endl;
    } // 无意义的对象拷贝

    A(A &&a)
    {
        std::cout << "移动" << std::endl;
    }
};

void independentThread(A *a)
{
    std::cout << "Starting concurrent thread.\n";
    std::this_thread::sleep_for(std::chrono::seconds(5));
    a->hello();
    std::cout << "Exiting concurrent thread.\n";
}

int main()
{
    std::cout << "Starting thread caller.\n";
    A *a = new A();
    a->hello();
    std::thread t(independentThread, a);
    t.detach();
    std::this_thread::sleep_for(std::chrono::seconds(2));
    std::cout << "Exiting thread caller.\n";
    // std::this_thread::sleep_for(std::chrono::seconds(5));
}